package com.example.Lezedata.ui.activity.goods;

import android.content.Context;
import android.os.Bundle;
import android.text.SpannableString;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.Lezedata.R;
import com.example.Lezedata.ui.activity.common.GBCell;
import com.example.Lezedata.util.GBTimeManager;
import com.example.Lezedata.util.GBUtil;

import bid.Bid;

public class BuyPersonCell extends FrameLayout {

    private ImageView head;
    private TextView mobile;
    private TextView bid;
    private TextView time;

    public Bid.BidRecordItem bidRecordItem;

    public static BuyPersonCell newInstance(Context context) {
        BuyPersonCell cell = (BuyPersonCell) LayoutInflater.from(context).inflate(R.layout.buy_person_cell,null,false);
        return cell;
    }

    public BuyPersonCell(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        head = findViewWithTag("head");
        mobile = findViewWithTag("mobile");
        bid = findViewWithTag("bid");
        time = findViewWithTag("time");
    }

    public void setBidRecordItem(Bid.BidRecordItem bidRecordItem) {
        this.bidRecordItem = bidRecordItem;
//        GBUtil.setHeadImage(head,bidRecordItem);
        mobile.setText(GBUtil.mobileReplaceToXxx(bidRecordItem.getPhone()));
        time.setText(GBTimeManager.timesYMD_HMS(bidRecordItem.getCreateTime()));

        String bStr = String.valueOf(bidRecordItem.getBidCount());
        String allS = String.format("Bought %s bids",bStr);
        int index = allS.indexOf(bStr);
        SpannableString spannableString = GBUtil.textAddColor(allS,getResources().getColor(R.color.app_color_main),index,index+bStr.length());
        bid.setText(spannableString);
    }
}
